Vector [] vs copying

Posted by sak on Stack Overflow See other posts from Stack Overflow or by sak
Published on 2010-04-11T09:34:13Z Indexed on 2010/04/11 9:43 UTC
Read the original article Hit count: 255

Filed under:
|
|
|
|

What is faster and/or generally better?

vector<myType> myVec;
int i;
myType current;

for( i = 0; i < 1000000; i ++ )
{
 current = myVec[ i ];
 doSomethingWith( current );
 doAlotMoreWith( current );
 messAroundWith( current );
 checkSomeValuesOf( current );
}

or

vector<myType> myVec;
int i;

for( i = 0; i < 1000000; i ++ )
{
 doSomethingWith( myVec[ i ] );
 doAlotMoreWith( myVec[ i ] );
 messAroundWith( myVec[ i ] );
 checkSomeValuesOf( myVec[ i ] );
}

I'm currently using the first solution. There are really millions of calls per second and every single bit comparison/move is performance-problematic.

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl